# 科赫曲线绘制
import turtle


def koch(size, n):
    if n == 0:
        turtle.fd(size)
    else:
        for angle in [0, 60, -120, 60]:
            turtle.left(angle)
            # 这里除3是为了防止更改n时图形大小变化过大
            koch(size / 3, n - 1)


def draw(size, level, turn):
    for i in range(turn):
        turtle.right(360 / turn)
        koch(size, level)


def main():
    turtle.speed(0)
    turtle.hideturtle()
    turtle.title("科赫曲线绘制")
    turtle.hideturtle()
    turtle.setup(800, 800)
    turtle.penup()
    turtle.goto(-200, 200)
    turtle.pendown()
    turtle.pensize(2)
    # 雪花阶数
    level = 3
    size = 300
    # 转向次数
    turn = 3
    koch(size, level)
    draw(size, level, turn)
    turtle.done()


main()
